package com.ssm.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ssm.base.BaseController;
import com.ssm.entity.Dict;
import com.ssm.result.Result;
import com.ssm.service.DictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author jie_ge
 * @Date 2022/4/18
 */
@Controller
@RequestMapping("/dict")
public class DictController extends BaseController {
    @Reference
    private DictService dictService;

    /**
     * 根据上级的id获取子节点数据列表
     * @param id
     * @return
     */
    @GetMapping("/findZNodes")
    @ResponseBody
    public Result findByParentId(@RequestParam(value = "id",defaultValue = "0") Long id){
        List<Map<String, Object>> zNodes = dictService.findZNodes(id);
        return Result.ok(zNodes);
    }

    /**
     * 跳转到首页
     * @return
     */
    @GetMapping
    public String index(){
        return "dict/index";
    }

    /**
     * 根据上一级的id获取子节点数据列表
     * @param parentId
     * @return
     */
    @GetMapping("/findListByParentId/{parentId}")
    @ResponseBody
    public Result<List<Dict>> findListByParentId(@PathVariable Long parentId){
        List<Dict> list = dictService.findListByParentId(parentId);
        return Result.ok(list);
    }

    /**
     * 根据编码获取子节点的数据列表
     * @param dictCode
     * @return
     */
    @GetMapping("/findListByDictCode/{dictCode}")
    @ResponseBody
    public Result<List<Dict>> findListByDictCode(@PathVariable String dictCode){
        List<Dict> list = dictService.findListByDictCode(dictCode);
        return Result.ok(list);
    }
}
